//
//  ViewController.m
//  KKUtils
//
//  Created by jay Win on 2019/10/16.
//  Copyright © 2019 jay Win. All rights reserved.
//

#import "ViewController.h"
#import "KKUtils.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray<NSString *> *dataSource;

@end

@implementation ViewController

-(NSArray<NSString *> *)dataSource{
    if (!_dataSource) {
        _dataSource = @[
            @"震动",
            @"发送邮件",
            @"展示评论框",
            @"复制内容到剪切版",
            @"是否安装应用",
            @"本地分享",
            @"ins分享",
            @"保存资源到相册",
            @"检查相机权限",
            @"检查相册权限",
            @"请求相机权限",
            @"请求相册权限",
            @"获取本地语言",
            @"获取本地地区",
            @"是否为Ipad",
            @"检查线上版本更新"
        ];
    }
    return _dataSource;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self construstTableView];
}

-(void)construstTableView {
    self.tableView.backgroundColor = UIColor.whiteColor;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // cell 的点击方法
    NSLog(@"-- kksdk.utils --: 点击了%ld", indexPath.row);
    NSString *path = [[NSBundle mainBundle] pathForResource:@"testImage" ofType:@"jpg"];
    KKUtils *util = [KKUtils new];
    switch (indexPath.row) {
        case 0:
            [util vibrator:1];
            break;
        case 1:
            [util sendEmail:self emailAddress:@"example@test.com" title:@"test title" productName:@"com.kksdk.utils"];
            break;
        case 2:
            [util showCommentDialog];
            break;
        case 3:
            [util copyStringToClipboard:@"我是复制的内容"];
            break;
        case 4:
            [util hasInstallApp:@""];
            break;
        case 5:
            [util shareNative:self filePath:path];
            break;
        case 6:
            [util shareToInstagram:path complete:^(BOOL isSuccess, NSError * _Nullable error) {
                
            }];
            break;
        case 7:
            [util saveToAlbum:path complete:^(BOOL isSuccess, NSString * _Nullable assetLocalID, NSError * _Nullable error) {
                NSLog(@"保存结果：%d，%@，%@", isSuccess, assetLocalID, error);
            }];
            break;
        case 8:
            [util checkCameraPermission];
            break;
        case 9:
            [util checkAlbumPermission];
            break;
        case 10:
            [util requestCameraPermission:^(BOOL hasPermisssion) {
                
            }];
            break;
        case 11:
            [util requestAlbumPermission:^(BOOL hasPermisssion) {
                
            }];
            break;
        case 12:
            [util getLanguage];
            break;
        case 13:
            [util getLocale];
            break;
        case 14:
            [util isIPad];
        case 15:
            [util checkUpdateAppVersion:@"2.1.1" title:@"APP有更新啦" positive:@"确认" negative:@"取消" message:@"有版本更新啦"];
        default:
            break;
    }
}

#pragma mark - UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = self.dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 35;
}

@end
